const path = require("path");
const CopyWebpackPlugin = require('copy-webpack-plugin');
const webpack = require("webpack");

module.exports = {
	mode: "development",
	entry: "./web/index.js",
	output: {
		filename: "index.js",
		path: path.resolve(__dirname, "./dist")
	},
	module: {
		rules: [
			{
				test: /\.css$/,
				use: [ 'style-loader', 'css-loader' ]
			},
			{
				test: /\.js$/,
				exclude: /(node_modules)/,
				use: {
					loader: "babel-loader",
					options: {
						presets: ["@babel/preset-react", "@babel/preset-env", ]
					}
				}
			}
		]
	},
	plugins: [
		new CopyWebpackPlugin([
			{from: "./web/dist/index.js", to: "../../server/public/javascripts/"},
			{from: "./web/dist/index.js.map", to: "../../server/public/javascripts/"}
		])
	],
	devtool: "source-map", 
	watch: true,
	watchOptions: {
		aggregateTimeout: 300,
		poll: 1000
	}
};